"""
python正则表达式re模块的3个基础匹配方法
    1.match：从第一个字符开始匹配，匹配成功返回匹配对象（包含匹配信息），匹配不成功返回空
    2.search：搜索整个字符串，找到匹配的。从前向后，找到第一个后就停止，不会继续向后搜索
    3.findall：匹配整个字符串，找出全部的匹配项
"""

import re

# -----------------match ----------------------- #
my_str = "go python java"
result = re.match("python", my_str)
print(result)
if result: 
    print(result.span())
    print(result.group())

# -----------------search ----------------------- #

search_str = "1python java go"
search_result = re.search("python2", search_str)
print(search_result)
if search_result:
    print(search_result.span())
    print(search_result.group())

# -----------------findall ----------------------- #
findall_str = "1python java go python java"
findall_list = re.findall("python", findall_str)
print(findall_list)
